//store.jsx

"use client";
import React, { PropsWithChildren, useEffect } from 'react';
import { Provider, useDispatch } from 'react-redux';
import { configureStore } from '@reduxjs/toolkit';

/** 要注册到全局的 reducer */
import './modules/counter/slice';
import { getGlobalReducer, initGlobalSlices } from '@/pao/web';


export const store = configureStore({
    reducer: getGlobalReducer(),
});

export const ReduxProvider: React.FC<PropsWithChildren<{}>> = function ({ children }) {
    useEffect(()=> {
        initGlobalSlices(store);
    })
    return <Provider store={store}>{children}</Provider>;
}

export type RootState = ReturnType<typeof store.getState>;

export type AppDispatch = typeof store.dispatch;

export function useAppDispatch() {
    return useDispatch<AppDispatch>();
}